<?php

/**
 * This is the model class for table "parts".
 *
 * The followings are the available columns in table 'parts':
 * @property string $id
 * @property string $part_code
 * @property string $name
 * @property string $lead_time_days
 * @property string $unit_code
 * @property string $description
 * @property string $id_categories
 * @property string $id_subcategories
 * @property string $id_section
 * @property string $id_process
 * @property string $id_status
 * @property string $item_id
 * @property string $status_part
 * @property string $supplier_code
 * @property string $part_maker
 * @property string $min_order_qty
 * @property string $re_order_level
 * @property string $unit_of_measure
 * @property string $section_name
 * @property double $price
 * @property string $currency
 * @property string $current_stock
 * @property string $status_po
 * @property string $part
 * @property string $item_code
 * @property string $actual_qty
 * @property string $status_stock
 * @property string $max_stock
 * @property string $min_stock
 * @property string $stock_taking
 * @property string $mrp
 * @property string $jumlah
 * @property string $currency_code
 * @property string $inspection_received
 * @property string $inspection_rejected
 * @property integer $is_new_item
 * @property string $link_part_code
 * @property string $part_kind
 *
 * The followings are the available model relations:
 * @property ItemStatus $idStatus
 * @property ItemCategories $idCategories
 * @property ItemSubcategories $idSubcategories
 * @property ItemSection $idSection
 * @property ItemProcess $idProcess
 */
class Parts extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Parts the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'parts';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('part_code', 'required'),
			array('is_new_item', 'numerical', 'integerOnly'=>true),
			array('price', 'numerical'),
			array('part_code', 'length', 'max'=>100),
			array('lead_time_days, id_categories, id_subcategories, id_section, id_process, id_status, item_id, supplier_code, min_order_qty, re_order_level, current_stock, item_code, actual_qty, max_stock, min_stock, jumlah, inspection_received, inspection_rejected', 'length', 'max'=>19),
			array('unit_code, part_maker, unit_of_measure, section_name, currency, status_po, part, status_stock, stock_taking, mrp, currency_code, link_part_code, part_kind', 'length', 'max'=>50),
			array('status_part', 'length', 'max'=>5),
			array('name, description', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, part_code, name, lead_time_days, unit_code, description, id_categories, id_subcategories, id_section, id_process, id_status, item_id, status_part, supplier_code, part_maker, min_order_qty, re_order_level, unit_of_measure, section_name, price, currency, current_stock, status_po, part, item_code, actual_qty, status_stock, max_stock, min_stock, stock_taking, mrp, jumlah, currency_code, inspection_received, inspection_rejected, is_new_item, link_part_code, part_kind', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'idStatus' => array(self::BELONGS_TO, 'ItemStatus', 'id_status'),
			'idCategories' => array(self::BELONGS_TO, 'ItemCategories', 'id_categories'),
			'idSubcategories' => array(self::BELONGS_TO, 'ItemSubcategories', 'id_subcategories'),
			'idSection' => array(self::BELONGS_TO, 'ItemSection', 'id_section'),
			'idProcess' => array(self::BELONGS_TO, 'ItemProcess', 'id_process'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'part_code' => 'Part Code',
			'name' => 'Name',
			'lead_time_days' => 'Lead Time Days',
			'unit_code' => 'Unit Code',
			'description' => 'Description',
			'id_categories' => 'Id Categories',
			'id_subcategories' => 'Id Subcategories',
			'id_section' => 'Id Section',
			'id_process' => 'Id Process',
			'id_status' => 'Id Status',
			'item_id' => 'Item',
			'status_part' => 'Status Part',
			'supplier_code' => 'Supplier Code',
			'part_maker' => 'Part Maker',
			'min_order_qty' => 'Min Order Qty',
			're_order_level' => 'Re Order Level',
			'unit_of_measure' => 'Unit Of Measure',
			'section_name' => 'Section Name',
			'price' => 'Price',
			'currency' => 'Currency',
			'current_stock' => 'Current Stock',
			'status_po' => 'Status Po',
			'part' => 'Part',
			'item_code' => 'Item Code',
			'actual_qty' => 'Actual Qty',
			'status_stock' => 'Status Stock',
			'max_stock' => 'Max Stock',
			'min_stock' => 'Min Stock',
			'stock_taking' => 'Stock Taking',
			'mrp' => 'Mrp',
			'jumlah' => 'Jumlah',
			'currency_code' => 'Currency Code',
			'inspection_received' => 'Inspection Received',
			'inspection_rejected' => 'Inspection Rejected',
			'is_new_item' => 'Is New Item',
			'link_part_code' => 'Link Part Code',
			'part_kind' => 'Part Kind',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('part_code',$this->part_code,true);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('lead_time_days',$this->lead_time_days,true);
		$criteria->compare('unit_code',$this->unit_code,true);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('id_categories',$this->id_categories,true);
		$criteria->compare('id_subcategories',$this->id_subcategories,true);
		$criteria->compare('id_section',$this->id_section,true);
		$criteria->compare('id_process',$this->id_process,true);
		$criteria->compare('id_status',$this->id_status,true);
		$criteria->compare('item_id',$this->item_id,true);
		$criteria->compare('status_part',$this->status_part,true);
		$criteria->compare('supplier_code',$this->supplier_code,true);
		$criteria->compare('part_maker',$this->part_maker,true);
		$criteria->compare('min_order_qty',$this->min_order_qty,true);
		$criteria->compare('re_order_level',$this->re_order_level,true);
		$criteria->compare('unit_of_measure',$this->unit_of_measure,true);
		$criteria->compare('section_name',$this->section_name,true);
		$criteria->compare('price',$this->price);
		$criteria->compare('currency',$this->currency,true);
		$criteria->compare('current_stock',$this->current_stock,true);
		$criteria->compare('status_po',$this->status_po,true);
		$criteria->compare('part',$this->part,true);
		$criteria->compare('item_code',$this->item_code,true);
		$criteria->compare('actual_qty',$this->actual_qty,true);
		$criteria->compare('status_stock',$this->status_stock,true);
		$criteria->compare('max_stock',$this->max_stock,true);
		$criteria->compare('min_stock',$this->min_stock,true);
		$criteria->compare('stock_taking',$this->stock_taking,true);
		$criteria->compare('mrp',$this->mrp,true);
		$criteria->compare('jumlah',$this->jumlah,true);
		$criteria->compare('currency_code',$this->currency_code,true);
		$criteria->compare('inspection_received',$this->inspection_received,true);
		$criteria->compare('inspection_rejected',$this->inspection_rejected,true);
		$criteria->compare('is_new_item',$this->is_new_item);
		$criteria->compare('link_part_code',$this->link_part_code,true);
		$criteria->compare('part_kind',$this->part_kind,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}